{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "6_recbyFM_LR.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/GavinHacker/recsys_model/blob/master/6_recbyFM_LR.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "metadata": {
        "id": "RNHdO789kRS5",
        "colab_type": "code",
        "outputId": "601569c5-1d89-40c5-cacc-ecb9b8fcb28a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 122
        }
      },
      "cell_type": "code",
      "source": [
        "!pip install pymysql"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Collecting pymysql\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47kB)\n",
            "\u001b[K    100% |████████████████████████████████| 51kB 3.5MB/s \n",
            "\u001b[?25hInstalling collected packages: pymysql\n",
            "Successfully installed pymysql-0.9.3\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "hxp0S1fvkVZJ",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "aIJ9cGs4o4gk",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "import pymysql\n",
        "import pymysql.cursors\n",
        "from functools import reduce\n",
        "import numpy as np\n",
        "import pandas as pd\n",
        "import uuid\n",
        "import datetime\n",
        "#from pyfm import pylibfm\n",
        "from sklearn.feature_extraction import DictVectorizer\n",
        "from sklearn.metrics.pairwise import pairwise_distances\n",
        "np.set_printoptions(precision=3)\n",
        "np.set_printoptions(suppress=True)\n",
        "from sklearn.datasets import dump_svmlight_file\n",
        "from sklearn.preprocessing import OneHotEncoder\n",
        "import pickle as pkl\n",
        "from sklearn.metrics import roc_auc_score, mean_squared_error\n",
        "from sklearn.datasets import load_svmlight_file\n",
        "from sklearn.linear_model import LogisticRegression"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "ROxDVkRfpCep",
        "colab_type": "code",
        "outputId": "d078bc48-20f0-4067-cedc-3cfc90b00db1",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 122
        }
      },
      "cell_type": "code",
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdocs.test%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.photos.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fpeopleapi.readonly&response_type=code\n",
            "\n",
            "Enter your authorization code:\n",
            "··········\n",
            "Mounted at /content/drive\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "WzmmEhBUpLsV",
        "colab_type": "code",
        "outputId": "ea92be8d-c107-45bc-c168-770cdec029e9",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "!ls"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "drive  sample_data\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "Jp64t_AOpa39",
        "colab_type": "code",
        "outputId": "5a80ae2a-c09b-48a3-db67-38d9c9d50b2c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        }
      },
      "cell_type": "code",
      "source": [
        "# !wget http://www.libfm.org/libfm-1.42.src.tar.gz\n",
        "!git clone https://github.com/srendle/libfm.git"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Cloning into 'libfm'...\n",
            "remote: Enumerating objects: 233, done.\u001b[K\n",
            "remote: Total 233 (delta 0), reused 0 (delta 0), pack-reused 233\u001b[K\n",
            "Receiving objects: 100% (233/233), 126.86 KiB | 1.01 MiB/s, done.\n",
            "Resolving deltas: 100% (113/113), done.\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "lko9EbvDloYx",
        "colab_type": "code",
        "outputId": "14ea303c-c4ac-4e17-bba5-5376cc6ce57d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "ls"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "\u001b[0m\u001b[01;34mdrive\u001b[0m/  \u001b[01;34mlibfm\u001b[0m/  \u001b[01;34msample_data\u001b[0m/\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "QPNrS8gApgzt",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        " #!tar -xzvf libfm-1.42.src.tar.gz"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "AoYkwnpVpoKM",
        "colab_type": "code",
        "outputId": "a9b01ef6-5a07-42f5-af4c-48d01aeb9e16",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "cd libfm"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/content/libfm\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "lLH7M-_Ops-V",
        "colab_type": "code",
        "outputId": "33802ccb-512f-40d7-b8d4-fe73159e337a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 221
        }
      },
      "cell_type": "code",
      "source": [
        "#%cd libfm-1.42.src/\n",
        "#!ls\n",
        "!make all"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "cd src/libfm; make all\n",
            "make[1]: Entering directory '/content/libfm/src/libfm'\n",
            "g++ -O3 -Wall -c libfm.cpp -o libfm.o\n",
            "mkdir -p ../../bin/\n",
            "g++ -O3 -Wall libfm.o -o ../../bin/libFM\n",
            "g++ -O3 -Wall -c tools/transpose.cpp -o tools/transpose.o\n",
            "mkdir -p ../../bin/\n",
            "g++ -O3 tools/transpose.o -o ../../bin/transpose\n",
            "g++ -O3 -Wall -c tools/convert.cpp -o tools/convert.o\n",
            "mkdir -p ../../bin/\n",
            "g++ -O3 tools/convert.o -o ../../bin/convert\n",
            "make[1]: Leaving directory '/content/libfm/src/libfm'\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "TbBd7BjGpxd-",
        "colab_type": "code",
        "outputId": "84bbaf05-76ff-459c-ec3f-8fe80ca2cda5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "cd bin"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/content/libfm/bin\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "a4q0pfoUp9DM",
        "colab_type": "code",
        "outputId": "fe4f8a98-1506-47c4-b1ed-de5c4c6497d5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "# /content/libfm-1.42.src/bin\n",
        "#cd /content/libfm-1.42.src/bin/\n",
        "ls"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "\u001b[0m\u001b[01;32mconvert\u001b[0m*  \u001b[01;32mlibFM\u001b[0m*  \u001b[01;32mtranspose\u001b[0m*\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "53tcWj73rg1N",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "LIBFM_PATH = '/content/libfm/bin/libFM'\n",
        "model_path = '/content/drive/My\\ Drive/colabnotebook/recsysmode.fm'"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "8LyBscFJs514",
        "colab_type": "code",
        "outputId": "9f1a5dab-a4a5-4314-801d-5aaea63a74d6",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 578
        }
      },
      "cell_type": "code",
      "source": [
        "!$LIBFM_PATH"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "----------------------------------------------------------------------------\n",
            "libFM\n",
            "  Version: 1.4.4\n",
            "  Author:  Steffen Rendle, srendle@libfm.org\n",
            "  WWW:     http://www.libfm.org/\n",
            "This program comes with ABSOLUTELY NO WARRANTY; for details see license.txt.\n",
            "This is free software, and you are welcome to redistribute it under certain\n",
            "conditions; for details see license.txt.\n",
            "----------------------------------------------------------------------------\n",
            "-cache_size     cache size for data storage (only applicable if data is\n",
            "                in binary format), default=infty\n",
            "-dim            'k0,k1,k2': k0=use bias, k1=use 1-way interactions,\n",
            "                k2=dim of 2-way interactions; default=1,1,8\n",
            "-help           this screen\n",
            "-init_stdev     stdev for initialization of 2-way factors; default=0.1\n",
            "-iter           number of iterations; default=100\n",
            "-learn_rate     learn_rate for SGD; default=0.1\n",
            "-load_model     filename for reading the FM model\n",
            "-meta           filename for meta information about data set\n",
            "-method         learning method (SGD, SGDA, ALS, MCMC); default=MCMC\n",
            "-out            filename for output\n",
            "-regular        'r0,r1,r2' for SGD and ALS: r0=bias regularization,\n",
            "                r1=1-way regularization, r2=2-way regularization\n",
            "-relation       BS: filenames for the relations, default=''\n",
            "-rlog           write measurements within iterations to a file;\n",
            "                default=''\n",
            "-save_model     filename for writing the FM model\n",
            "-seed           integer value, default=None\n",
            "-task           r=regression, c=binary classification [MANDATORY]\n",
            "-test           filename for test data [MANDATORY]\n",
            "-train          filename for training data [MANDATORY]\n",
            "-validation     filename for validation data (only for SGDA)\n",
            "-verbosity      how much infos to print; default=0\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "qmN_3atl9ttZ",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## FM模型训练和预测，使用libFM库蒙特卡洛法"
      ]
    },
    {
      "metadata": {
        "id": "bWCWPj9sqFJ8",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "def FM(train_file, test_file, classification=True, rank=10, n_iter=150):\n",
        "    task = 'c' if classification else 'r'\n",
        "    console_output = !$LIBFM_PATH -task $task -method mcmc -train $train_file -test $test_file -iter $n_iter -dim '1,1,$rank'  -out output_.libfm\n",
        "    #console_output = !$LIBFM_PATH -task $task -method als -regular '0,0,10' -train $train_file -test $test_file -iter $n_iter -dim '1,1,$rank' -save_model recsysmode.fm -out output_.libfm\n",
        "    #console_output = !$LIBFM_PATH -task $task -method sgd -train $train_file -test $test_file -iter $n_iter -dim '1,1,$rank' -save_model recsysmode.fm -out output_.libfm\n",
        "    print(console_output)\n",
        "    libfm_pred = pd.read_csv('output_.libfm', header=None).values.flatten()\n",
        "    return libfm_pred"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "bdRCZdzqqwGS",
        "colab_type": "code",
        "outputId": "2a9fb35a-b443-4b90-d4e2-1a9ab84348cd",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 54
        }
      },
      "cell_type": "code",
      "source": [
        "#train_file = '/content/drive/My\\ Drive/colabnotebook/recsys_train.txt'\n",
        "#test_file = '/content/drive/My\\ Drive/colabnotebook/recsys_test.txt'\n",
        "\n",
        "train_file = '/content/drive/My\\ Drive/colabnotebook/recsys_train_scaling.txt'\n",
        "test_file = '/content/drive/My\\ Drive/colabnotebook/recsys_test_scaling.txt'\n",
        "\n",
        "libfm_predict = FM(train_file, test_file, classification=False)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "['----------------------------------------------------------------------------', 'libFM', '  Version: 1.4.4', '  Author:  Steffen Rendle, srendle@libfm.org', '  WWW:     http://www.libfm.org/', 'This program comes with ABSOLUTELY NO WARRANTY; for details see license.txt.', 'This is free software, and you are welcome to redistribute it under certain', 'conditions; for details see license.txt.', '----------------------------------------------------------------------------', 'Loading train...\\t', 'has x = 0', 'has xt = 1', 'num_rows=280000\\tnum_values=6371577\\tnum_features=75619\\tmin_target=1\\tmax_target=5', 'Loading test... \\t', 'has x = 0', 'has xt = 1', 'num_rows=9152\\tnum_values=210368\\tnum_features=75616\\tmin_target=1\\tmax_target=5', '#relations: 0', 'Loading meta data...\\t', '#Iter=  0\\tTrain=1.01452\\tTest=0.890629', '#Iter=  1\\tTrain=0.892031\\tTest=0.663158', '#Iter=  2\\tTrain=0.876464\\tTest=0.55274', '#Iter=  3\\tTrain=0.871274\\tTest=0.490338', '#Iter=  4\\tTrain=0.868145\\tTest=0.45136', '#Iter=  5\\tTrain=0.866241\\tTest=0.425289', '#Iter=  6\\tTrain=0.863716\\tTest=0.409053', '#Iter=  7\\tTrain=0.861866\\tTest=0.39688', '#Iter=  8\\tTrain=0.859769\\tTest=0.389392', '#Iter=  9\\tTrain=0.858909\\tTest=0.382396', '#Iter= 10\\tTrain=0.857158\\tTest=0.376957', '#Iter= 11\\tTrain=0.855871\\tTest=0.372286', '#Iter= 12\\tTrain=0.854298\\tTest=0.368145', '#Iter= 13\\tTrain=0.853987\\tTest=0.364164', '#Iter= 14\\tTrain=0.852789\\tTest=0.360826', '#Iter= 15\\tTrain=0.852637\\tTest=0.358273', '#Iter= 16\\tTrain=0.851279\\tTest=0.355325', '#Iter= 17\\tTrain=0.849881\\tTest=0.352691', '#Iter= 18\\tTrain=0.850015\\tTest=0.350718', '#Iter= 19\\tTrain=0.849584\\tTest=0.348719', '#Iter= 20\\tTrain=0.849643\\tTest=0.346604', '#Iter= 21\\tTrain=0.848737\\tTest=0.344592', '#Iter= 22\\tTrain=0.848808\\tTest=0.342577', '#Iter= 23\\tTrain=0.848337\\tTest=0.340636', '#Iter= 24\\tTrain=0.847621\\tTest=0.339204', '#Iter= 25\\tTrain=0.847687\\tTest=0.337732', '#Iter= 26\\tTrain=0.847144\\tTest=0.336423', '#Iter= 27\\tTrain=0.846682\\tTest=0.335031', '#Iter= 28\\tTrain=0.846564\\tTest=0.33394', '#Iter= 29\\tTrain=0.846317\\tTest=0.332796', '#Iter= 30\\tTrain=0.846002\\tTest=0.332045', '#Iter= 31\\tTrain=0.845611\\tTest=0.330931', '#Iter= 32\\tTrain=0.845902\\tTest=0.32994', '#Iter= 33\\tTrain=0.844957\\tTest=0.32897', '#Iter= 34\\tTrain=0.845363\\tTest=0.327965', '#Iter= 35\\tTrain=0.844956\\tTest=0.326842', '#Iter= 36\\tTrain=0.844463\\tTest=0.325889', '#Iter= 37\\tTrain=0.844208\\tTest=0.324751', '#Iter= 38\\tTrain=0.843906\\tTest=0.323933', '#Iter= 39\\tTrain=0.843754\\tTest=0.323171', '#Iter= 40\\tTrain=0.843342\\tTest=0.322456', '#Iter= 41\\tTrain=0.842929\\tTest=0.321818', '#Iter= 42\\tTrain=0.842752\\tTest=0.321197', '#Iter= 43\\tTrain=0.842333\\tTest=0.320638', '#Iter= 44\\tTrain=0.842228\\tTest=0.320275', '#Iter= 45\\tTrain=0.841798\\tTest=0.319736', '#Iter= 46\\tTrain=0.841728\\tTest=0.319167', '#Iter= 47\\tTrain=0.841597\\tTest=0.318565', '#Iter= 48\\tTrain=0.84162\\tTest=0.318042', '#Iter= 49\\tTrain=0.841529\\tTest=0.317307', '#Iter= 50\\tTrain=0.840054\\tTest=0.3167', '#Iter= 51\\tTrain=0.840508\\tTest=0.316235', '#Iter= 52\\tTrain=0.840285\\tTest=0.315618', '#Iter= 53\\tTrain=0.840392\\tTest=0.315053', '#Iter= 54\\tTrain=0.839959\\tTest=0.314592', '#Iter= 55\\tTrain=0.839198\\tTest=0.31428', '#Iter= 56\\tTrain=0.838716\\tTest=0.313937', '#Iter= 57\\tTrain=0.838447\\tTest=0.31357', '#Iter= 58\\tTrain=0.838092\\tTest=0.313298', '#Iter= 59\\tTrain=0.837444\\tTest=0.313017', '#Iter= 60\\tTrain=0.837068\\tTest=0.312747', '#Iter= 61\\tTrain=0.836561\\tTest=0.312452', '#Iter= 62\\tTrain=0.836372\\tTest=0.312068', '#Iter= 63\\tTrain=0.836426\\tTest=0.311752', '#Iter= 64\\tTrain=0.836162\\tTest=0.31151', '#Iter= 65\\tTrain=0.836148\\tTest=0.311262', '#Iter= 66\\tTrain=0.835866\\tTest=0.31092', '#Iter= 67\\tTrain=0.835245\\tTest=0.310705', '#Iter= 68\\tTrain=0.834926\\tTest=0.310427', '#Iter= 69\\tTrain=0.834628\\tTest=0.310137', '#Iter= 70\\tTrain=0.833729\\tTest=0.309921', '#Iter= 71\\tTrain=0.833644\\tTest=0.30959', '#Iter= 72\\tTrain=0.833364\\tTest=0.30929', '#Iter= 73\\tTrain=0.83362\\tTest=0.309038', '#Iter= 74\\tTrain=0.83253\\tTest=0.308857', '#Iter= 75\\tTrain=0.833062\\tTest=0.308628', '#Iter= 76\\tTrain=0.832741\\tTest=0.30844', '#Iter= 77\\tTrain=0.831517\\tTest=0.308278', '#Iter= 78\\tTrain=0.8312\\tTest=0.308056', '#Iter= 79\\tTrain=0.830558\\tTest=0.307815', '#Iter= 80\\tTrain=0.830527\\tTest=0.307542', '#Iter= 81\\tTrain=0.83027\\tTest=0.307246', '#Iter= 82\\tTrain=0.82933\\tTest=0.30692', '#Iter= 83\\tTrain=0.829191\\tTest=0.306722', '#Iter= 84\\tTrain=0.828877\\tTest=0.30649', '#Iter= 85\\tTrain=0.829559\\tTest=0.30626', '#Iter= 86\\tTrain=0.828282\\tTest=0.306003', '#Iter= 87\\tTrain=0.828134\\tTest=0.305714', '#Iter= 88\\tTrain=0.827099\\tTest=0.305512', '#Iter= 89\\tTrain=0.826225\\tTest=0.305213', '#Iter= 90\\tTrain=0.825132\\tTest=0.304976', '#Iter= 91\\tTrain=0.824059\\tTest=0.304793', '#Iter= 92\\tTrain=0.823557\\tTest=0.304577', '#Iter= 93\\tTrain=0.823692\\tTest=0.304378', '#Iter= 94\\tTrain=0.823281\\tTest=0.304173', '#Iter= 95\\tTrain=0.822318\\tTest=0.303918', '#Iter= 96\\tTrain=0.820399\\tTest=0.303706', '#Iter= 97\\tTrain=0.820739\\tTest=0.303495', '#Iter= 98\\tTrain=0.819729\\tTest=0.303263', '#Iter= 99\\tTrain=0.818734\\tTest=0.302992', '#Iter=100\\tTrain=0.818642\\tTest=0.30276', '#Iter=101\\tTrain=0.818455\\tTest=0.302509', '#Iter=102\\tTrain=0.818081\\tTest=0.302313', '#Iter=103\\tTrain=0.816964\\tTest=0.302121', '#Iter=104\\tTrain=0.816384\\tTest=0.301915', '#Iter=105\\tTrain=0.815349\\tTest=0.301641', '#Iter=106\\tTrain=0.814405\\tTest=0.301394', '#Iter=107\\tTrain=0.813846\\tTest=0.301187', '#Iter=108\\tTrain=0.813869\\tTest=0.300911', '#Iter=109\\tTrain=0.812327\\tTest=0.300672', '#Iter=110\\tTrain=0.812539\\tTest=0.300456', '#Iter=111\\tTrain=0.813028\\tTest=0.300212', '#Iter=112\\tTrain=0.81073\\tTest=0.300022', '#Iter=113\\tTrain=0.810325\\tTest=0.299856', '#Iter=114\\tTrain=0.809163\\tTest=0.299653', '#Iter=115\\tTrain=0.80809\\tTest=0.299513', '#Iter=116\\tTrain=0.808267\\tTest=0.299332', '#Iter=117\\tTrain=0.807807\\tTest=0.299196', '#Iter=118\\tTrain=0.806707\\tTest=0.299003', '#Iter=119\\tTrain=0.80644\\tTest=0.298879', '#Iter=120\\tTrain=0.806213\\tTest=0.298708', '#Iter=121\\tTrain=0.805813\\tTest=0.298518', '#Iter=122\\tTrain=0.805164\\tTest=0.298354', '#Iter=123\\tTrain=0.80554\\tTest=0.298288', '#Iter=124\\tTrain=0.804707\\tTest=0.298111', '#Iter=125\\tTrain=0.804323\\tTest=0.29796', '#Iter=126\\tTrain=0.80366\\tTest=0.297828', '#Iter=127\\tTrain=0.803182\\tTest=0.297708', '#Iter=128\\tTrain=0.803205\\tTest=0.297554', '#Iter=129\\tTrain=0.802823\\tTest=0.297378', '#Iter=130\\tTrain=0.802491\\tTest=0.297182', '#Iter=131\\tTrain=0.802236\\tTest=0.297014', '#Iter=132\\tTrain=0.801736\\tTest=0.296828', '#Iter=133\\tTrain=0.801267\\tTest=0.296652', '#Iter=134\\tTrain=0.801098\\tTest=0.296475', '#Iter=135\\tTrain=0.801036\\tTest=0.296307', '#Iter=136\\tTrain=0.800896\\tTest=0.296186', '#Iter=137\\tTrain=0.800412\\tTest=0.296063', '#Iter=138\\tTrain=0.800397\\tTest=0.295926', '#Iter=139\\tTrain=0.799815\\tTest=0.295802', '#Iter=140\\tTrain=0.798848\\tTest=0.295706', '#Iter=141\\tTrain=0.79897\\tTest=0.295553', '#Iter=142\\tTrain=0.799084\\tTest=0.295465', '#Iter=143\\tTrain=0.798128\\tTest=0.295401', '#Iter=144\\tTrain=0.798342\\tTest=0.295269', '#Iter=145\\tTrain=0.798554\\tTest=0.295161', '#Iter=146\\tTrain=0.79779\\tTest=0.295083', '#Iter=147\\tTrain=0.797289\\tTest=0.294956', '#Iter=148\\tTrain=0.797838\\tTest=0.294852', '#Iter=149\\tTrain=0.797072\\tTest=0.294716']\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "mP0mkrLku7qH",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "#train_file_without_escape = '/content/drive/My Drive/colabnotebook/recsys_test.txt'\n",
        "train_file_without_escape_path = '/content/drive/My Drive/colabnotebook/recsys_test_scaling.txt'\n",
        "\n",
        "def get_test_data(path):\n",
        "    data = load_svmlight_file(path)\n",
        "    return data[0], data[1]"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "bq_FTh58pHlo",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "X, y = get_test_data(train_file_without_escape_path)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "gyXkwNcfvPCn",
        "colab_type": "code",
        "outputId": "dcc8b1a1-6655-46cd-a6e8-863ccb514db6",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "y"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([2., 2., 2., ..., 5., 4., 4.])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 20
        }
      ]
    },
    {
      "metadata": {
        "id": "4VWXqv7ovkO1",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "libfm_predict_series = pd.Series(libfm_predict)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "7CRAxgNVv2uG",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "libfm_predict_series_int = libfm_predict_series.apply(lambda x:int(x))"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "5nbN4IWmv9OW",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "libfm_predict_series_int.tolist()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "hqUC-WK__4C1",
        "colab_type": "code",
        "outputId": "26431487-506d-49e6-9f80-6d8a62d4632a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "y"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([2., 2., 2., ..., 5., 4., 4.])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 25
        }
      ]
    },
    {
      "metadata": {
        "id": "sTbVfKtH97IT",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## 转换为评分后的测试集MSE"
      ]
    },
    {
      "metadata": {
        "id": "LMBNGhk8rVQn",
        "colab_type": "code",
        "outputId": "82567af4-35eb-4a56-938a-963494c9013e",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "mean_squared_error(y, libfm_predict_series_int.tolist())"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.502076048951049"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 26
        }
      ]
    },
    {
      "metadata": {
        "id": "DjX4a8s7pm84",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "#libfm_predict_series"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "i24SrPPQpUVg",
        "colab_type": "code",
        "outputId": "3293f3c2-ad54-4aa5-f4d3-fdd54cdf3f36",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "mean_squared_error(y, libfm_predict_series.tolist())"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.08685760569920237"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 28
        }
      ]
    },
    {
      "metadata": {
        "id": "WUnC8-MeulWQ",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# mse 0.5673076923076923"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "XcacNKW_p0gl",
        "colab_type": "code",
        "outputId": "ef73cfce-b114-4852-b9fe-f98daff9a853",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "y[0:10]"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([2., 2., 2., 2., 2., 1., 1., 2., 2., 2.])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 30
        }
      ]
    },
    {
      "metadata": {
        "id": "m2FDgodCp2fE",
        "colab_type": "code",
        "outputId": "760a6c06-64e5-4eab-f706-3979d4c1dd08",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1071
        }
      },
      "cell_type": "code",
      "source": [
        "libfm_predict_series[100:500]"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "100    1.97529\n",
              "101    1.97529\n",
              "102    2.18110\n",
              "103    2.18110\n",
              "104    2.12399\n",
              "105    2.12399\n",
              "106    1.13479\n",
              "107    1.13479\n",
              "108    2.28783\n",
              "109    2.28783\n",
              "110    1.55382\n",
              "111    1.55382\n",
              "112    1.57852\n",
              "113    1.95209\n",
              "114    1.95209\n",
              "115    2.11365\n",
              "116    2.11365\n",
              "117    1.88502\n",
              "118    1.88502\n",
              "119    1.92887\n",
              "120    1.92887\n",
              "121    2.12270\n",
              "122    2.12270\n",
              "123    1.83748\n",
              "124    1.83748\n",
              "125    1.91633\n",
              "126    1.91633\n",
              "127    1.96745\n",
              "128    1.96745\n",
              "129    1.96745\n",
              "        ...   \n",
              "470    1.80736\n",
              "471    2.27779\n",
              "472    2.27779\n",
              "473    1.87991\n",
              "474    1.02377\n",
              "475    1.05935\n",
              "476    1.76910\n",
              "477    1.73278\n",
              "478    1.73839\n",
              "479    1.67171\n",
              "480    1.96251\n",
              "481    2.04542\n",
              "482    1.26207\n",
              "483    2.12236\n",
              "484    1.64691\n",
              "485    4.03943\n",
              "486    4.93219\n",
              "487    4.94244\n",
              "488    4.94952\n",
              "489    4.93831\n",
              "490    4.03264\n",
              "491    4.94984\n",
              "492    4.92404\n",
              "493    4.93621\n",
              "494    4.11513\n",
              "495    4.96065\n",
              "496    4.94856\n",
              "497    4.93610\n",
              "498    4.95667\n",
              "499    4.94818\n",
              "Length: 400, dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 31
        }
      ]
    },
    {
      "metadata": {
        "id": "ZmYkr3aEKwfs",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "def get_connection():\n",
        "    return pymysql.connect(host='rm-2zeqqm6994abi7b6dqo.mysql.rds.aliyuncs.com',\n",
        "                               user='noone',\n",
        "                               password='Huawei12#$',\n",
        "                               db='recsys',\n",
        "                               port=3306,\n",
        "                               charset ='utf8',\n",
        "                               use_unicode=True)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "e50cXhH03hAW",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "userid_collection = pd.read_sql_query(\"select id from system_user\", get_connection())"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "_eTP6X7T4nMk",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "#for userid in userid_collection['id'].tolist():\n",
        "  #userproex_sql = 'select * from userproex_new where userid = \\'%s\\'' % userid\n",
        "  #movie_sql = 'select * from movie where id in (select DISTINCT movieid from recmovie where userid=\\'%s\\')' % userid\n",
        "  #movie_sql = 'select * from movie left join recmovie on movie.id=recmovie.movieid where recmovie.userid = \\'%s\\'' % userid\n",
        "  #df_user_pro = pd.read_sql_query(userproex_sql, get_connection())\n",
        "  #df_movie = pd.read_sql_query(movie_sql, get_connection())\n",
        "  #df_data = pd.merge(df_movie, df_user_pro, how='left', left_on=['userid'], right_on=['userid']) "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "N1pkxSG0-Z3v",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## 对生产数据进行预测"
      ]
    },
    {
      "metadata": {
        "id": "u1xc-QFRGfPZ",
        "colab_type": "code",
        "outputId": "94e20923-799f-419c-a077-eb0ad3b56d4b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1009
        }
      },
      "cell_type": "code",
      "source": [
        "sql = 'select * from recmovie left join movie on movie.id=recmovie.movieid left join userproex_new on userproex_new.userid=recmovie.userid'\n",
        "df_data = pd.read_sql_query(sql, get_connection())\n",
        "df_data = df_data.drop([0], axis=1)\n",
        "#df_data = df_data.rename(columns = {'userid':'USERID'})\n",
        "#df_data['USERID'].fillna(0)\n",
        "print(df_data.columns)\n",
        "df_data = df_data.loc[:,~df_data.columns.duplicated()]\n",
        "#print(df_data.shape)\n",
        "df_data = df_data.rename(columns = {'userid':'USERID'})\n",
        "df_data['TIME_DIS'] = np.zeros(df_data.shape[0])\n",
        "df_data.T"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Index(['id', 'userid', 'movieid', 'rectime', 'lrrat', 'fmrat', 'srcmovieid',\n",
            "       'id', 'name', 'ADD_TIME', 'type', 'actors', 'region', 'director',\n",
            "       'trait', 'rat', 'enable', 'description', 'img', 'userid', 'rmax',\n",
            "       'rmin', 'ravg', 'rcount', 'rsum', 'rmedian'],\n",
            "      dtype='object')\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>0</th>\n",
              "      <th>1</th>\n",
              "      <th>2</th>\n",
              "      <th>3</th>\n",
              "      <th>4</th>\n",
              "      <th>5</th>\n",
              "      <th>6</th>\n",
              "      <th>7</th>\n",
              "      <th>8</th>\n",
              "      <th>9</th>\n",
              "      <th>...</th>\n",
              "      <th>358</th>\n",
              "      <th>359</th>\n",
              "      <th>360</th>\n",
              "      <th>361</th>\n",
              "      <th>362</th>\n",
              "      <th>363</th>\n",
              "      <th>364</th>\n",
              "      <th>365</th>\n",
              "      <th>366</th>\n",
              "      <th>367</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>id</th>\n",
              "      <td>1</td>\n",
              "      <td>4</td>\n",
              "      <td>2</td>\n",
              "      <td>5</td>\n",
              "      <td>6</td>\n",
              "      <td>7</td>\n",
              "      <td>ae80cb2c-99c4-4797-9255-d5fd4a839a89</td>\n",
              "      <td>f39e0456-95dc-4d2f-8c28-4e133f0373fa</td>\n",
              "      <td>3642bc8f-4db7-4070-b42a-ba3a3e86ebc2</td>\n",
              "      <td>8a82a843-4855-4166-84bb-df1dd863f473</td>\n",
              "      <td>...</td>\n",
              "      <td>c34d35a8-311a-4104-8928-f681d21cb772</td>\n",
              "      <td>c345df00-0477-492c-a54c-d9891fdd9191</td>\n",
              "      <td>0fd2493e-fa20-4b83-be0e-11d103173ce9</td>\n",
              "      <td>162643e3-2267-4868-bf82-cc93077b8042</td>\n",
              "      <td>77ac2672-0a53-476e-b7a4-96483eb4d438</td>\n",
              "      <td>b0796180-1a2a-417f-963b-fb569ca6a3de</td>\n",
              "      <td>1f38ed3d-b0b8-4231-b63f-24e7b4d2c75d</td>\n",
              "      <td>84b9f462-2316-48d4-8246-fccc3e6686d1</td>\n",
              "      <td>6de81408-671f-44a4-8647-710c20990ca0</td>\n",
              "      <td>48fcb7d2-c6da-4b54-a2cd-cc089d1732a6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>USERID</th>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>...</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>movieid</th>\n",
              "      <td>10001432</td>\n",
              "      <td>10438426</td>\n",
              "      <td>10430817</td>\n",
              "      <td>10428476</td>\n",
              "      <td>10480973</td>\n",
              "      <td>10430817</td>\n",
              "      <td>1293143</td>\n",
              "      <td>1298574</td>\n",
              "      <td>26279449</td>\n",
              "      <td>1300077</td>\n",
              "      <td>...</td>\n",
              "      <td>4861404</td>\n",
              "      <td>1506769</td>\n",
              "      <td>26801782</td>\n",
              "      <td>6876154</td>\n",
              "      <td>25920885</td>\n",
              "      <td>1483239</td>\n",
              "      <td>1293828</td>\n",
              "      <td>25925430</td>\n",
              "      <td>1292288</td>\n",
              "      <td>25824009</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>rectime</th>\n",
              "      <td>2019-01-03 17:15:16</td>\n",
              "      <td>2019-01-03 17:15:16</td>\n",
              "      <td>2019-01-03 17:15:16</td>\n",
              "      <td>2019-01-03 17:15:17</td>\n",
              "      <td>2019-01-03 17:15:17</td>\n",
              "      <td>2019-01-03 17:15:17</td>\n",
              "      <td>2019-01-03 17:15:17</td>\n",
              "      <td>2019-01-03 17:15:18</td>\n",
              "      <td>2019-01-03 17:15:18</td>\n",
              "      <td>2019-01-03 17:15:18</td>\n",
              "      <td>...</td>\n",
              "      <td>2019-01-03 17:16:13</td>\n",
              "      <td>2019-01-03 17:16:13</td>\n",
              "      <td>2019-01-03 17:16:13</td>\n",
              "      <td>2019-01-03 17:16:13</td>\n",
              "      <td>2019-01-03 17:16:14</td>\n",
              "      <td>2019-01-03 17:16:14</td>\n",
              "      <td>2019-01-03 17:16:14</td>\n",
              "      <td>2019-01-03 17:16:14</td>\n",
              "      <td>2019-01-03 17:16:14</td>\n",
              "      <td>2019-01-03 17:16:14</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>lrrat</th>\n",
              "      <td>0.9566560968670121</td>\n",
              "      <td>0.7094158164093888</td>\n",
              "      <td>0.9246206977608482</td>\n",
              "      <td>0.9709013664018189</td>\n",
              "      <td>0.9943388169360198</td>\n",
              "      <td>0.9923293856012846</td>\n",
              "      <td>0.9892911847499388</td>\n",
              "      <td>0.9917181316565221</td>\n",
              "      <td>0.9779553256545537</td>\n",
              "      <td>0.9882757142751645</td>\n",
              "      <td>...</td>\n",
              "      <td>0.9804026653224612</td>\n",
              "      <td>0.9922989548864766</td>\n",
              "      <td>0.994322264278463</td>\n",
              "      <td>0.9871967461477341</td>\n",
              "      <td>0.9838058080674467</td>\n",
              "      <td>0.9864132321966126</td>\n",
              "      <td>0.9951047425199501</td>\n",
              "      <td>0.9907983080150248</td>\n",
              "      <td>0.9897209977315697</td>\n",
              "      <td>0.9411134313614328</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>fmrat</th>\n",
              "      <td>5.0</td>\n",
              "      <td>4.9844599999999994</td>\n",
              "      <td>5.0</td>\n",
              "      <td>4.013330000000001</td>\n",
              "      <td>4.01579</td>\n",
              "      <td>4.013330000000001</td>\n",
              "      <td>4.01565</td>\n",
              "      <td>4.0202800000000005</td>\n",
              "      <td>4.01428</td>\n",
              "      <td>4.03078</td>\n",
              "      <td>...</td>\n",
              "      <td>4.013330000000001</td>\n",
              "      <td>3.99511</td>\n",
              "      <td>3.9866699999999997</td>\n",
              "      <td>4.013330000000001</td>\n",
              "      <td>4.0149300000000006</td>\n",
              "      <td>4.01015</td>\n",
              "      <td>4.013330000000001</td>\n",
              "      <td>3.9866699999999997</td>\n",
              "      <td>4.00569</td>\n",
              "      <td>4.01436</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>srcmovieid</th>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>1294941</td>\n",
              "      <td>1294941</td>\n",
              "      <td>1294941</td>\n",
              "      <td>1294941</td>\n",
              "      <td>...</td>\n",
              "      <td>10727641</td>\n",
              "      <td>10727641</td>\n",
              "      <td>10727641</td>\n",
              "      <td>10727641</td>\n",
              "      <td>10727641</td>\n",
              "      <td>10727641</td>\n",
              "      <td>10727641</td>\n",
              "      <td>10727641</td>\n",
              "      <td>10727641</td>\n",
              "      <td>10727641</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>name</th>\n",
              "      <td>颠倒的帕特玛</td>\n",
              "      <td>浮城谜事</td>\n",
              "      <td>隐墙</td>\n",
              "      <td>小屁孩日记3</td>\n",
              "      <td>圣斗士星矢：圣域传说</td>\n",
              "      <td>隐墙</td>\n",
              "      <td>13号星期五</td>\n",
              "      <td>机器战警2</td>\n",
              "      <td>蒸发太平洋</td>\n",
              "      <td>鬼娃回魂</td>\n",
              "      <td>...</td>\n",
              "      <td>超能力者</td>\n",
              "      <td>ABC谋杀案</td>\n",
              "      <td>缉枪</td>\n",
              "      <td>国家利益</td>\n",
              "      <td>神探夏洛克：可恶的新娘</td>\n",
              "      <td>夺命枪火</td>\n",
              "      <td>007之金手指</td>\n",
              "      <td>真相</td>\n",
              "      <td>公民凯恩</td>\n",
              "      <td>脑残粉</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>ADD_TIME</th>\n",
              "      <td>2018-02-07 20:46:08</td>\n",
              "      <td>2018-02-07 20:26:53</td>\n",
              "      <td>2018-02-07 21:03:06</td>\n",
              "      <td>2018-02-07 20:47:00</td>\n",
              "      <td>2018-02-07 20:38:14</td>\n",
              "      <td>2018-02-07 21:03:06</td>\n",
              "      <td>2018-02-07 20:55:17</td>\n",
              "      <td>2018-02-07 20:43:08</td>\n",
              "      <td>2018-02-07 20:46:29</td>\n",
              "      <td>2018-02-07 20:41:36</td>\n",
              "      <td>...</td>\n",
              "      <td>2018-02-07 20:53:16</td>\n",
              "      <td>2018-02-07 21:03:17</td>\n",
              "      <td>2018-02-07 20:54:01</td>\n",
              "      <td>2018-02-07 20:49:14</td>\n",
              "      <td>2018-02-07 20:22:24</td>\n",
              "      <td>2018-02-07 20:37:16</td>\n",
              "      <td>2018-02-07 20:41:36</td>\n",
              "      <td>2018-02-07 20:52:29</td>\n",
              "      <td>Fri Jan  5 11:36:09 2018</td>\n",
              "      <td>2018-02-07 20:56:03</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>type</th>\n",
              "      <td>剧情|冒险|科幻|爱情</td>\n",
              "      <td>剧情|犯罪|悬疑|爱情</td>\n",
              "      <td>剧情|奇幻|悬疑|科幻</td>\n",
              "      <td>剧情|喜剧</td>\n",
              "      <td>奇幻|冒险|科幻|动作</td>\n",
              "      <td>剧情|奇幻|悬疑|科幻</td>\n",
              "      <td>悬疑|犯罪|惊悚|恐怖</td>\n",
              "      <td>犯罪|科幻|惊悚|动作</td>\n",
              "      <td>惊悚|剧情|犯罪|悬疑|科幻|冒险|动作</td>\n",
              "      <td>悬疑|惊悚|恐怖</td>\n",
              "      <td>...</td>\n",
              "      <td>奇幻|惊悚|剧情|犯罪|悬疑|科幻|动作</td>\n",
              "      <td>剧情|犯罪|悬疑</td>\n",
              "      <td>剧情|犯罪|悬疑|动作</td>\n",
              "      <td>惊悚|爱情|剧情|犯罪|悬疑|动作</td>\n",
              "      <td>剧情|犯罪|悬疑|惊悚</td>\n",
              "      <td>惊悚|剧情|犯罪|悬疑|冒险|动作</td>\n",
              "      <td>犯罪|冒险|惊悚|动作</td>\n",
              "      <td>剧情|犯罪|悬疑|传记|历史</td>\n",
              "      <td>剧情|犯罪|悬疑|传记</td>\n",
              "      <td>惊悚|剧情|犯罪|悬疑|喜剧|歌舞|恐怖|动作</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>actors</th>\n",
              "      <td>藤井雪代|冈本信彦|大畑伸太郎|福松进纱|加藤将之</td>\n",
              "      <td>郝蕾|秦昊|齐溪|朱亚文|祖锋</td>\n",
              "      <td>马蒂娜·格德克|Karlheinz Hackl|Wolfgang M|Bauer|Ulrik...</td>\n",
              "      <td>扎克瑞·戈登|瑞秋·哈里斯|戴文·博斯蒂克|罗伯特·卡普荣|佩顿·李斯特</td>\n",
              "      <td>石川界人|赤羽根健治|小野贤章|冈本信彦|野岛健儿</td>\n",
              "      <td>马蒂娜·格德克|Karlheinz Hackl|Wolfgang M|Bauer|Ulrik...</td>\n",
              "      <td>贝丝蒂·帕尔默|凯文·贝肯</td>\n",
              "      <td>彼得·威勒|南茜·艾伦|加布里埃尔·达蒙|莉扎·吉邦斯</td>\n",
              "      <td>布兰登·罗斯|张雨绮|王盛德|维森特·M|沃德|戴向宇</td>\n",
              "      <td>凯瑟琳·海克丝|克里斯·萨兰登|艾力克斯·文森特|布拉德·道里夫|黛娜·马诺夫</td>\n",
              "      <td>...</td>\n",
              "      <td>姜栋元|高修|郑恩彩</td>\n",
              "      <td>大卫·苏切|休·弗拉瑟|菲利普·杰克森</td>\n",
              "      <td>白举纲|热依扎|连奕名|任东霖|童苡萱</td>\n",
              "      <td>米卡埃尔·佩斯布兰特|萨巴·穆巴拉克|大卫·丹席克|潘妮拉·奥古斯特|杰森·弗莱明</td>\n",
              "      <td>本尼迪克特·康伯巴奇|马丁·弗瑞曼|尤娜·斯塔布斯|鲁珀特·格雷夫斯|马克·加蒂斯</td>\n",
              "      <td>保罗·沃克|卡梅隆·布莱特|维拉·法米加|查兹·帕尔明特瑞|卡瑞尔·罗登</td>\n",
              "      <td>肖恩·康纳利|霍纳尔·布莱克曼|杰特·弗罗比|雪莉·伊顿|坦妮娅·玛蕾特</td>\n",
              "      <td>何家勁|郭可盈|金超群</td>\n",
              "      <td>Richard Ben Cramer|威廉·阿伦德|彼得·博格丹诺维奇</td>\n",
              "      <td>沙鲁克·汗|瓦妮·卡普尔|保罗·布莱克维尔|玛瑞沃拉·嘉沃斯卡|李·尼古拉斯·哈里斯</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>region</th>\n",
              "      <td>日本</td>\n",
              "      <td>法国</td>\n",
              "      <td>德国</td>\n",
              "      <td>加拿大</td>\n",
              "      <td>日本</td>\n",
              "      <td>德国</td>\n",
              "      <td>美国</td>\n",
              "      <td>美国</td>\n",
              "      <td>美国</td>\n",
              "      <td>美国</td>\n",
              "      <td>...</td>\n",
              "      <td>韩国</td>\n",
              "      <td>英国</td>\n",
              "      <td>中国大陆</td>\n",
              "      <td>瑞典</td>\n",
              "      <td>英国</td>\n",
              "      <td>德国</td>\n",
              "      <td>英国</td>\n",
              "      <td>香港</td>\n",
              "      <td>美国</td>\n",
              "      <td>印度</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>director</th>\n",
              "      <td>吉浦康裕</td>\n",
              "      <td>娄烨</td>\n",
              "      <td>Julian Pölsler</td>\n",
              "      <td>大卫·博维斯</td>\n",
              "      <td>佐藤敬一</td>\n",
              "      <td>Julian Pölsler</td>\n",
              "      <td>肖恩·S·坎宁安</td>\n",
              "      <td>厄文·克什纳</td>\n",
              "      <td>周文武贝</td>\n",
              "      <td>汤姆·霍兰德</td>\n",
              "      <td>...</td>\n",
              "      <td>金民锡</td>\n",
              "      <td>安德鲁·格里弗</td>\n",
              "      <td>徐兵</td>\n",
              "      <td>凯瑟琳·温德菲尔德</td>\n",
              "      <td>道格拉斯·麦金农</td>\n",
              "      <td>韦恩·克雷默</td>\n",
              "      <td>盖伊·汉弥尔顿</td>\n",
              "      <td>邱禮濤</td>\n",
              "      <td>Michael Epstein|Thomas Lennon</td>\n",
              "      <td>玛尼什·莎玛</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>trait</th>\n",
              "      <td>青春</td>\n",
              "      <td>女性|文艺</td>\n",
              "      <td>文艺</td>\n",
              "      <td>青春|搞笑</td>\n",
              "      <td>青春|经典|魔幻</td>\n",
              "      <td>文艺</td>\n",
              "      <td>经典</td>\n",
              "      <td>经典</td>\n",
              "      <td>搞笑</td>\n",
              "      <td>经典</td>\n",
              "      <td>...</td>\n",
              "      <td>魔幻</td>\n",
              "      <td>经典</td>\n",
              "      <td>经典</td>\n",
              "      <td>经典</td>\n",
              "      <td>经典</td>\n",
              "      <td>黑帮</td>\n",
              "      <td>经典</td>\n",
              "      <td>女性|经典|文艺</td>\n",
              "      <td>经典</td>\n",
              "      <td>搞笑</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>rat</th>\n",
              "      <td>7.9</td>\n",
              "      <td>7.3</td>\n",
              "      <td>7.4</td>\n",
              "      <td>6.7</td>\n",
              "      <td>6.3</td>\n",
              "      <td>7.4</td>\n",
              "      <td>6.3</td>\n",
              "      <td>6.9</td>\n",
              "      <td>3.4</td>\n",
              "      <td>6.8</td>\n",
              "      <td>...</td>\n",
              "      <td>5.7</td>\n",
              "      <td>8.1</td>\n",
              "      <td>6.3</td>\n",
              "      <td>6.7</td>\n",
              "      <td>6.9</td>\n",
              "      <td>7.7</td>\n",
              "      <td>7.1</td>\n",
              "      <td>7.7</td>\n",
              "      <td>7.6</td>\n",
              "      <td>6.6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>enable</th>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>...</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>description</th>\n",
              "      <td>在秩序井然的艾嘉王国，人类谨遵祖先的教训，绝不抬头仰望苍穹，放纵思绪流淌狂奔。传说在很久以前...</td>\n",
              "      <td>警察童明松（祖锋 饰）负责调查一起车祸，大学生蚊子（常方源 饰） 意外惨死，童明松决定同哥们...</td>\n",
              "      <td>\"影片的主人公是一位并没有给出姓名的女人(马蒂娜·戈黛特《他人的生活》饰演)。她和两位朋友以...</td>\n",
              "      <td>又是一年暑假，顺利结束七年级学业的格雷格·赫夫利（扎克瑞·戈登 Zachary Gordon...</td>\n",
              "      <td>16年前，射手座黄金圣斗士艾欧洛斯怀抱真正的女神转世雅典娜逃出圣域，途中遭到双子座撒卡和摩羯...</td>\n",
              "      <td>\"影片的主人公是一位并没有给出姓名的女人(马蒂娜·戈黛特《他人的生活》饰演)。她和两位朋友以...</td>\n",
              "      <td>1958年，水晶湖营地发生一起两人死亡的命案，而这只是陆续发生在水晶湖旁的一系列凶案和怪事之...</td>\n",
              "      <td>在这部续集中，生产机械战警的泛消费公司掌控着底特律城的治安，警察们因薪水迟迟不能到位而举行罢...</td>\n",
              "      <td>《蒸发太平洋》讲述了一个发生于2020年的科幻冒险故事，一架大洋航空新客机在首航中遭遇意外，...</td>\n",
              "      <td>美国芝加哥的午夜，杀人犯雷在警探迈克（克里斯·萨兰登 Chris Sarandon ）的追捕...</td>\n",
              "      <td>...</td>\n",
              "      <td>从小，楚仁（姜东元饰）就知道自己拥有能够控制人心的超能力，凡是被他的双眼所正视的人，无一...</td>\n",
              "      <td>一个比波罗更强调秩序的人出现了。三个字母，三个地点，三宗凶案，三具尸体。 A代表第一个被谋杀...</td>\n",
              "      <td>一次普通的车辆剐蹭事故里，俞苗老公刘明义拿枪打死了徐天的女朋友，被警察当场击毙。徐天找俞苗赔...</td>\n",
              "      <td>本片被称为瑞典版007，男主角主演的《更好的世界》曾获得83届奥斯卡最佳外语片大奖。　　...</td>\n",
              "      <td>《神探夏洛克》（Sherlock）2016年推出特别篇，福尔摩斯回归原著维多利亚时代，调查一...</td>\n",
              "      <td>表面上看来，乔伊（保罗·沃克 Paul Walker 饰）过着人人羡慕的美满生活，温馨的房子...</td>\n",
              "      <td>世界各国突然出现黄金大量流失的现象，而黄金的黑市交易却十分兴盛。英国情报部怀疑世界巨富金手指...</td>\n",
              "      <td>索尼卖下《真相》的北美发行权，影片由凯特·布兰切特和罗伯特·雷德福主演，改编自《真相与责任：...</td>\n",
              "      <td>美国报业大亨凯恩（奥森•韦尔斯）在桑拿都庄园中留下“玫瑰花蕾”的“遗言”死去后，一位青年记者...</td>\n",
              "      <td>高瑞夫（沙鲁克·汗 饰）是德里一个网吧的小老板，自小就是超级巨星阿利安•坎纳（沙鲁克·汗 饰...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>img</th>\n",
              "      <td>https://img1.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img1.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img1.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img1.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img1.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img1.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "      <td>https://img3.doubanio.com/view/photo/s_ratio_p...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>rmax</th>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>...</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "      <td>5</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>rmin</th>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>...</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>ravg</th>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>...</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>3.85714</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>rcount</th>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>...</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "      <td>7</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>rsum</th>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>...</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "      <td>27</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>rmedian</th>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>3</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>...</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "      <td>4</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>TIME_DIS</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>25 rows × 368 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "                                                           0    \\\n",
              "id                                                           1   \n",
              "USERID                                                       1   \n",
              "movieid                                               10001432   \n",
              "rectime                                    2019-01-03 17:15:16   \n",
              "lrrat                                       0.9566560968670121   \n",
              "fmrat                                                      5.0   \n",
              "srcmovieid                                                       \n",
              "name                                                    颠倒的帕特玛   \n",
              "ADD_TIME                                   2018-02-07 20:46:08   \n",
              "type                                               剧情|冒险|科幻|爱情   \n",
              "actors                               藤井雪代|冈本信彦|大畑伸太郎|福松进纱|加藤将之   \n",
              "region                                                      日本   \n",
              "director                                                  吉浦康裕   \n",
              "trait                                                       青春   \n",
              "rat                                                        7.9   \n",
              "enable                                                       1   \n",
              "description  在秩序井然的艾嘉王国，人类谨遵祖先的教训，绝不抬头仰望苍穹，放纵思绪流淌狂奔。传说在很久以前...   \n",
              "img          https://img1.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         3   \n",
              "rmin                                                         3   \n",
              "ravg                                                         3   \n",
              "rcount                                                       1   \n",
              "rsum                                                         3   \n",
              "rmedian                                                      3   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           1    \\\n",
              "id                                                           4   \n",
              "USERID                                                       1   \n",
              "movieid                                               10438426   \n",
              "rectime                                    2019-01-03 17:15:16   \n",
              "lrrat                                       0.7094158164093888   \n",
              "fmrat                                       4.9844599999999994   \n",
              "srcmovieid                                                       \n",
              "name                                                      浮城谜事   \n",
              "ADD_TIME                                   2018-02-07 20:26:53   \n",
              "type                                               剧情|犯罪|悬疑|爱情   \n",
              "actors                                         郝蕾|秦昊|齐溪|朱亚文|祖锋   \n",
              "region                                                      法国   \n",
              "director                                                    娄烨   \n",
              "trait                                                    女性|文艺   \n",
              "rat                                                        7.3   \n",
              "enable                                                       1   \n",
              "description  警察童明松（祖锋 饰）负责调查一起车祸，大学生蚊子（常方源 饰） 意外惨死，童明松决定同哥们...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         3   \n",
              "rmin                                                         3   \n",
              "ravg                                                         3   \n",
              "rcount                                                       1   \n",
              "rsum                                                         3   \n",
              "rmedian                                                      3   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           2    \\\n",
              "id                                                           2   \n",
              "USERID                                                       1   \n",
              "movieid                                               10430817   \n",
              "rectime                                    2019-01-03 17:15:16   \n",
              "lrrat                                       0.9246206977608482   \n",
              "fmrat                                                      5.0   \n",
              "srcmovieid                                                       \n",
              "name                                                        隐墙   \n",
              "ADD_TIME                                   2018-02-07 21:03:06   \n",
              "type                                               剧情|奇幻|悬疑|科幻   \n",
              "actors       马蒂娜·格德克|Karlheinz Hackl|Wolfgang M|Bauer|Ulrik...   \n",
              "region                                                      德国   \n",
              "director                                        Julian Pölsler   \n",
              "trait                                                       文艺   \n",
              "rat                                                        7.4   \n",
              "enable                                                       1   \n",
              "description  \"影片的主人公是一位并没有给出姓名的女人(马蒂娜·戈黛特《他人的生活》饰演)。她和两位朋友以...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         3   \n",
              "rmin                                                         3   \n",
              "ravg                                                         3   \n",
              "rcount                                                       1   \n",
              "rsum                                                         3   \n",
              "rmedian                                                      3   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           3    \\\n",
              "id                                                           5   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                               10428476   \n",
              "rectime                                    2019-01-03 17:15:17   \n",
              "lrrat                                       0.9709013664018189   \n",
              "fmrat                                        4.013330000000001   \n",
              "srcmovieid                                                       \n",
              "name                                                    小屁孩日记3   \n",
              "ADD_TIME                                   2018-02-07 20:47:00   \n",
              "type                                                     剧情|喜剧   \n",
              "actors                    扎克瑞·戈登|瑞秋·哈里斯|戴文·博斯蒂克|罗伯特·卡普荣|佩顿·李斯特   \n",
              "region                                                     加拿大   \n",
              "director                                                大卫·博维斯   \n",
              "trait                                                    青春|搞笑   \n",
              "rat                                                        6.7   \n",
              "enable                                                       1   \n",
              "description  又是一年暑假，顺利结束七年级学业的格雷格·赫夫利（扎克瑞·戈登 Zachary Gordon...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           4    \\\n",
              "id                                                           6   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                               10480973   \n",
              "rectime                                    2019-01-03 17:15:17   \n",
              "lrrat                                       0.9943388169360198   \n",
              "fmrat                                                  4.01579   \n",
              "srcmovieid                                                       \n",
              "name                                                圣斗士星矢：圣域传说   \n",
              "ADD_TIME                                   2018-02-07 20:38:14   \n",
              "type                                               奇幻|冒险|科幻|动作   \n",
              "actors                               石川界人|赤羽根健治|小野贤章|冈本信彦|野岛健儿   \n",
              "region                                                      日本   \n",
              "director                                                  佐藤敬一   \n",
              "trait                                                 青春|经典|魔幻   \n",
              "rat                                                        6.3   \n",
              "enable                                                       1   \n",
              "description  16年前，射手座黄金圣斗士艾欧洛斯怀抱真正的女神转世雅典娜逃出圣域，途中遭到双子座撒卡和摩羯...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           5    \\\n",
              "id                                                           7   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                               10430817   \n",
              "rectime                                    2019-01-03 17:15:17   \n",
              "lrrat                                       0.9923293856012846   \n",
              "fmrat                                        4.013330000000001   \n",
              "srcmovieid                                                       \n",
              "name                                                        隐墙   \n",
              "ADD_TIME                                   2018-02-07 21:03:06   \n",
              "type                                               剧情|奇幻|悬疑|科幻   \n",
              "actors       马蒂娜·格德克|Karlheinz Hackl|Wolfgang M|Bauer|Ulrik...   \n",
              "region                                                      德国   \n",
              "director                                        Julian Pölsler   \n",
              "trait                                                       文艺   \n",
              "rat                                                        7.4   \n",
              "enable                                                       1   \n",
              "description  \"影片的主人公是一位并没有给出姓名的女人(马蒂娜·戈黛特《他人的生活》饰演)。她和两位朋友以...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           6    \\\n",
              "id                        ae80cb2c-99c4-4797-9255-d5fd4a839a89   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                                1293143   \n",
              "rectime                                    2019-01-03 17:15:17   \n",
              "lrrat                                       0.9892911847499388   \n",
              "fmrat                                                  4.01565   \n",
              "srcmovieid                                             1294941   \n",
              "name                                                    13号星期五   \n",
              "ADD_TIME                                   2018-02-07 20:55:17   \n",
              "type                                               悬疑|犯罪|惊悚|恐怖   \n",
              "actors                                           贝丝蒂·帕尔默|凯文·贝肯   \n",
              "region                                                      美国   \n",
              "director                                              肖恩·S·坎宁安   \n",
              "trait                                                       经典   \n",
              "rat                                                        6.3   \n",
              "enable                                                       1   \n",
              "description  1958年，水晶湖营地发生一起两人死亡的命案，而这只是陆续发生在水晶湖旁的一系列凶案和怪事之...   \n",
              "img          https://img1.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           7    \\\n",
              "id                        f39e0456-95dc-4d2f-8c28-4e133f0373fa   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                                1298574   \n",
              "rectime                                    2019-01-03 17:15:18   \n",
              "lrrat                                       0.9917181316565221   \n",
              "fmrat                                       4.0202800000000005   \n",
              "srcmovieid                                             1294941   \n",
              "name                                                     机器战警2   \n",
              "ADD_TIME                                   2018-02-07 20:43:08   \n",
              "type                                               犯罪|科幻|惊悚|动作   \n",
              "actors                             彼得·威勒|南茜·艾伦|加布里埃尔·达蒙|莉扎·吉邦斯   \n",
              "region                                                      美国   \n",
              "director                                                厄文·克什纳   \n",
              "trait                                                       经典   \n",
              "rat                                                        6.9   \n",
              "enable                                                       1   \n",
              "description  在这部续集中，生产机械战警的泛消费公司掌控着底特律城的治安，警察们因薪水迟迟不能到位而举行罢...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           8    \\\n",
              "id                        3642bc8f-4db7-4070-b42a-ba3a3e86ebc2   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                               26279449   \n",
              "rectime                                    2019-01-03 17:15:18   \n",
              "lrrat                                       0.9779553256545537   \n",
              "fmrat                                                  4.01428   \n",
              "srcmovieid                                             1294941   \n",
              "name                                                     蒸发太平洋   \n",
              "ADD_TIME                                   2018-02-07 20:46:29   \n",
              "type                                      惊悚|剧情|犯罪|悬疑|科幻|冒险|动作   \n",
              "actors                             布兰登·罗斯|张雨绮|王盛德|维森特·M|沃德|戴向宇   \n",
              "region                                                      美国   \n",
              "director                                                  周文武贝   \n",
              "trait                                                       搞笑   \n",
              "rat                                                        3.4   \n",
              "enable                                                       1   \n",
              "description  《蒸发太平洋》讲述了一个发生于2020年的科幻冒险故事，一架大洋航空新客机在首航中遭遇意外，...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           9    \\\n",
              "id                        8a82a843-4855-4166-84bb-df1dd863f473   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                                1300077   \n",
              "rectime                                    2019-01-03 17:15:18   \n",
              "lrrat                                       0.9882757142751645   \n",
              "fmrat                                                  4.03078   \n",
              "srcmovieid                                             1294941   \n",
              "name                                                      鬼娃回魂   \n",
              "ADD_TIME                                   2018-02-07 20:41:36   \n",
              "type                                                  悬疑|惊悚|恐怖   \n",
              "actors                 凯瑟琳·海克丝|克里斯·萨兰登|艾力克斯·文森特|布拉德·道里夫|黛娜·马诺夫   \n",
              "region                                                      美国   \n",
              "director                                                汤姆·霍兰德   \n",
              "trait                                                       经典   \n",
              "rat                                                        6.8   \n",
              "enable                                                       1   \n",
              "description  美国芝加哥的午夜，杀人犯雷在警探迈克（克里斯·萨兰登 Chris Sarandon ）的追捕...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                   ...                          \\\n",
              "id                                 ...                           \n",
              "USERID                             ...                           \n",
              "movieid                            ...                           \n",
              "rectime                            ...                           \n",
              "lrrat                              ...                           \n",
              "fmrat                              ...                           \n",
              "srcmovieid                         ...                           \n",
              "name                               ...                           \n",
              "ADD_TIME                           ...                           \n",
              "type                               ...                           \n",
              "actors                             ...                           \n",
              "region                             ...                           \n",
              "director                           ...                           \n",
              "trait                              ...                           \n",
              "rat                                ...                           \n",
              "enable                             ...                           \n",
              "description                        ...                           \n",
              "img                                ...                           \n",
              "rmax                               ...                           \n",
              "rmin                               ...                           \n",
              "ravg                               ...                           \n",
              "rcount                             ...                           \n",
              "rsum                               ...                           \n",
              "rmedian                            ...                           \n",
              "TIME_DIS                           ...                           \n",
              "\n",
              "                                                           358  \\\n",
              "id                        c34d35a8-311a-4104-8928-f681d21cb772   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                                4861404   \n",
              "rectime                                    2019-01-03 17:16:13   \n",
              "lrrat                                       0.9804026653224612   \n",
              "fmrat                                        4.013330000000001   \n",
              "srcmovieid                                            10727641   \n",
              "name                                                      超能力者   \n",
              "ADD_TIME                                   2018-02-07 20:53:16   \n",
              "type                                      奇幻|惊悚|剧情|犯罪|悬疑|科幻|动作   \n",
              "actors                                              姜栋元|高修|郑恩彩   \n",
              "region                                                      韩国   \n",
              "director                                                   金民锡   \n",
              "trait                                                       魔幻   \n",
              "rat                                                        5.7   \n",
              "enable                                                       1   \n",
              "description  　　从小，楚仁（姜东元饰）就知道自己拥有能够控制人心的超能力，凡是被他的双眼所正视的人，无一...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           359  \\\n",
              "id                        c345df00-0477-492c-a54c-d9891fdd9191   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                                1506769   \n",
              "rectime                                    2019-01-03 17:16:13   \n",
              "lrrat                                       0.9922989548864766   \n",
              "fmrat                                                  3.99511   \n",
              "srcmovieid                                            10727641   \n",
              "name                                                    ABC谋杀案   \n",
              "ADD_TIME                                   2018-02-07 21:03:17   \n",
              "type                                                  剧情|犯罪|悬疑   \n",
              "actors                                     大卫·苏切|休·弗拉瑟|菲利普·杰克森   \n",
              "region                                                      英国   \n",
              "director                                               安德鲁·格里弗   \n",
              "trait                                                       经典   \n",
              "rat                                                        8.1   \n",
              "enable                                                       1   \n",
              "description  一个比波罗更强调秩序的人出现了。三个字母，三个地点，三宗凶案，三具尸体。 A代表第一个被谋杀...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           360  \\\n",
              "id                        0fd2493e-fa20-4b83-be0e-11d103173ce9   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                               26801782   \n",
              "rectime                                    2019-01-03 17:16:13   \n",
              "lrrat                                        0.994322264278463   \n",
              "fmrat                                       3.9866699999999997   \n",
              "srcmovieid                                            10727641   \n",
              "name                                                        缉枪   \n",
              "ADD_TIME                                   2018-02-07 20:54:01   \n",
              "type                                               剧情|犯罪|悬疑|动作   \n",
              "actors                                     白举纲|热依扎|连奕名|任东霖|童苡萱   \n",
              "region                                                    中国大陆   \n",
              "director                                                    徐兵   \n",
              "trait                                                       经典   \n",
              "rat                                                        6.3   \n",
              "enable                                                       1   \n",
              "description  一次普通的车辆剐蹭事故里，俞苗老公刘明义拿枪打死了徐天的女朋友，被警察当场击毙。徐天找俞苗赔...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           361  \\\n",
              "id                        162643e3-2267-4868-bf82-cc93077b8042   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                                6876154   \n",
              "rectime                                    2019-01-03 17:16:13   \n",
              "lrrat                                       0.9871967461477341   \n",
              "fmrat                                        4.013330000000001   \n",
              "srcmovieid                                            10727641   \n",
              "name                                                      国家利益   \n",
              "ADD_TIME                                   2018-02-07 20:49:14   \n",
              "type                                         惊悚|爱情|剧情|犯罪|悬疑|动作   \n",
              "actors               米卡埃尔·佩斯布兰特|萨巴·穆巴拉克|大卫·丹席克|潘妮拉·奥古斯特|杰森·弗莱明   \n",
              "region                                                      瑞典   \n",
              "director                                             凯瑟琳·温德菲尔德   \n",
              "trait                                                       经典   \n",
              "rat                                                        6.7   \n",
              "enable                                                       1   \n",
              "description  　　本片被称为瑞典版007，男主角主演的《更好的世界》曾获得83届奥斯卡最佳外语片大奖。　　...   \n",
              "img          https://img1.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           362  \\\n",
              "id                        77ac2672-0a53-476e-b7a4-96483eb4d438   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                               25920885   \n",
              "rectime                                    2019-01-03 17:16:14   \n",
              "lrrat                                       0.9838058080674467   \n",
              "fmrat                                       4.0149300000000006   \n",
              "srcmovieid                                            10727641   \n",
              "name                                               神探夏洛克：可恶的新娘   \n",
              "ADD_TIME                                   2018-02-07 20:22:24   \n",
              "type                                               剧情|犯罪|悬疑|惊悚   \n",
              "actors               本尼迪克特·康伯巴奇|马丁·弗瑞曼|尤娜·斯塔布斯|鲁珀特·格雷夫斯|马克·加蒂斯   \n",
              "region                                                      英国   \n",
              "director                                              道格拉斯·麦金农   \n",
              "trait                                                       经典   \n",
              "rat                                                        6.9   \n",
              "enable                                                       1   \n",
              "description  《神探夏洛克》（Sherlock）2016年推出特别篇，福尔摩斯回归原著维多利亚时代，调查一...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           363  \\\n",
              "id                        b0796180-1a2a-417f-963b-fb569ca6a3de   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                                1483239   \n",
              "rectime                                    2019-01-03 17:16:14   \n",
              "lrrat                                       0.9864132321966126   \n",
              "fmrat                                                  4.01015   \n",
              "srcmovieid                                            10727641   \n",
              "name                                                      夺命枪火   \n",
              "ADD_TIME                                   2018-02-07 20:37:16   \n",
              "type                                         惊悚|剧情|犯罪|悬疑|冒险|动作   \n",
              "actors                    保罗·沃克|卡梅隆·布莱特|维拉·法米加|查兹·帕尔明特瑞|卡瑞尔·罗登   \n",
              "region                                                      德国   \n",
              "director                                                韦恩·克雷默   \n",
              "trait                                                       黑帮   \n",
              "rat                                                        7.7   \n",
              "enable                                                       1   \n",
              "description  表面上看来，乔伊（保罗·沃克 Paul Walker 饰）过着人人羡慕的美满生活，温馨的房子...   \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           364  \\\n",
              "id                        1f38ed3d-b0b8-4231-b63f-24e7b4d2c75d   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                                1293828   \n",
              "rectime                                    2019-01-03 17:16:14   \n",
              "lrrat                                       0.9951047425199501   \n",
              "fmrat                                        4.013330000000001   \n",
              "srcmovieid                                            10727641   \n",
              "name                                                   007之金手指   \n",
              "ADD_TIME                                   2018-02-07 20:41:36   \n",
              "type                                               犯罪|冒险|惊悚|动作   \n",
              "actors                    肖恩·康纳利|霍纳尔·布莱克曼|杰特·弗罗比|雪莉·伊顿|坦妮娅·玛蕾特   \n",
              "region                                                      英国   \n",
              "director                                               盖伊·汉弥尔顿   \n",
              "trait                                                       经典   \n",
              "rat                                                        7.1   \n",
              "enable                                                       1   \n",
              "description  世界各国突然出现黄金大量流失的现象，而黄金的黑市交易却十分兴盛。英国情报部怀疑世界巨富金手指...   \n",
              "img          https://img1.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           365  \\\n",
              "id                        84b9f462-2316-48d4-8246-fccc3e6686d1   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                               25925430   \n",
              "rectime                                    2019-01-03 17:16:14   \n",
              "lrrat                                       0.9907983080150248   \n",
              "fmrat                                       3.9866699999999997   \n",
              "srcmovieid                                            10727641   \n",
              "name                                                        真相   \n",
              "ADD_TIME                                   2018-02-07 20:52:29   \n",
              "type                                            剧情|犯罪|悬疑|传记|历史   \n",
              "actors                                             何家勁|郭可盈|金超群   \n",
              "region                                                      香港   \n",
              "director                                                   邱禮濤   \n",
              "trait                                                 女性|经典|文艺   \n",
              "rat                                                        7.7   \n",
              "enable                                                       1   \n",
              "description  索尼卖下《真相》的北美发行权，影片由凯特·布兰切特和罗伯特·雷德福主演，改编自《真相与责任：...   \n",
              "img          https://img1.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           366  \\\n",
              "id                        6de81408-671f-44a4-8647-710c20990ca0   \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f   \n",
              "movieid                                                1292288   \n",
              "rectime                                    2019-01-03 17:16:14   \n",
              "lrrat                                       0.9897209977315697   \n",
              "fmrat                                                  4.00569   \n",
              "srcmovieid                                            10727641   \n",
              "name                                                      公民凯恩   \n",
              "ADD_TIME                              Fri Jan  5 11:36:09 2018   \n",
              "type                                               剧情|犯罪|悬疑|传记   \n",
              "actors                     Richard Ben Cramer|威廉·阿伦德|彼得·博格丹诺维奇   \n",
              "region                                                      美国   \n",
              "director                         Michael Epstein|Thomas Lennon   \n",
              "trait                                                       经典   \n",
              "rat                                                        7.6   \n",
              "enable                                                       1   \n",
              "description  美国报业大亨凯恩（奥森•韦尔斯）在桑拿都庄园中留下“玫瑰花蕾”的“遗言”死去后，一位青年记者...   \n",
              "img          https://img1.doubanio.com/view/photo/s_ratio_p...   \n",
              "rmax                                                         5   \n",
              "rmin                                                         2   \n",
              "ravg                                                   3.85714   \n",
              "rcount                                                       7   \n",
              "rsum                                                        27   \n",
              "rmedian                                                      4   \n",
              "TIME_DIS                                                     0   \n",
              "\n",
              "                                                           367  \n",
              "id                        48fcb7d2-c6da-4b54-a2cd-cc089d1732a6  \n",
              "USERID                        cf2349f9c01f9a5cd4050aebd30ab74f  \n",
              "movieid                                               25824009  \n",
              "rectime                                    2019-01-03 17:16:14  \n",
              "lrrat                                       0.9411134313614328  \n",
              "fmrat                                                  4.01436  \n",
              "srcmovieid                                            10727641  \n",
              "name                                                       脑残粉  \n",
              "ADD_TIME                                   2018-02-07 20:56:03  \n",
              "type                                   惊悚|剧情|犯罪|悬疑|喜剧|歌舞|恐怖|动作  \n",
              "actors              沙鲁克·汗|瓦妮·卡普尔|保罗·布莱克维尔|玛瑞沃拉·嘉沃斯卡|李·尼古拉斯·哈里斯  \n",
              "region                                                      印度  \n",
              "director                                                玛尼什·莎玛  \n",
              "trait                                                       搞笑  \n",
              "rat                                                        6.6  \n",
              "enable                                                       1  \n",
              "description  高瑞夫（沙鲁克·汗 饰）是德里一个网吧的小老板，自小就是超级巨星阿利安•坎纳（沙鲁克·汗 饰...  \n",
              "img          https://img3.doubanio.com/view/photo/s_ratio_p...  \n",
              "rmax                                                         5  \n",
              "rmin                                                         2  \n",
              "ravg                                                   3.85714  \n",
              "rcount                                                       7  \n",
              "rsum                                                        27  \n",
              "rmedian                                                      4  \n",
              "TIME_DIS                                                     0  \n",
              "\n",
              "[25 rows x 368 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 35
        }
      ]
    },
    {
      "metadata": {
        "id": "jfqzU_3dNwsB",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "3YSUMJP-NRxq",
        "colab_type": "code",
        "outputId": "48a938ff-2653-4fc7-84e9-11a6eb9476a6",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "print(df_data.shape)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(368, 25)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "jI6d3XzZ27PX",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "##df_user_pro = pd.read_sql_query(\"select * from userproex_new where \", get_connection())\n",
        "##df_movie = pd.read_sql_query(\"select * from movie\", get_connection())"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "94m6JPDm-gK0",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## 需要保存向量转换器"
      ]
    },
    {
      "metadata": {
        "id": "UBhbE3yNp38k",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "v_from_pkl = None\n",
        "with open('/content/drive/My Drive/colabnotebook/dict2vec', 'rb') as f:\n",
        "  v_from_pkl = pkl.load(f)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "CaF2nBdM26gZ",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "-i9m5sEWqep3",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "# df_predict = pd.DataFrame(v_from_pkl.transform(predict).todense())\n",
        "# df_predict[df_predict > 0].T.dropna()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "OGjQdKOUsE13",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "#np.zeros(libfm_predict_series.shape[0]).shape"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "fSr8gmUisHEj",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "#dump_svmlight_file(testX, numpy.zeros(testX.shape[0]), '/content/drive/My Drive/colabnotebook/recsys_predict.txt')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "wxbT_tdo-kIs",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## 保存频度统计字典"
      ]
    },
    {
      "metadata": {
        "id": "maRwHN6JvNCR",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "actors_dict = None\n",
        "director_dict = None\n",
        "\n",
        "with open('/content/drive/My Drive/colabnotebook/actors_dict', 'rb') as f:\n",
        "  actors_dict = pkl.load(f)\n",
        "  \n",
        "with open('/content/drive/My Drive/colabnotebook/director_dict', 'rb') as f:\n",
        "  director_dict = pkl.load(f)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "jUpkQuWB-ols",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## 与训练样本一样的方式构建预测数据的输入矩阵"
      ]
    },
    {
      "metadata": {
        "id": "zEYLhp72u6st",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "def convert_dataframe_2_dict_list(df_main, actors_dict, director_dict):\n",
        "  data_dict_list = []\n",
        "  for i in df_main.index:\n",
        "    _dict = {}\n",
        "    is_invalid = False\n",
        "    #type\n",
        "    for s_type in df_main.iloc[i]['type'].split('|'):\n",
        "      _dict[s_type] = 1\n",
        "    #actors\n",
        "    for s_actor in df_main.iloc[i]['actors'].split('|'):\n",
        "      if not s_actor in actors_dict:\n",
        "        print('invalid data index is ' + str(i))\n",
        "        invalid_data_list.append(i)\n",
        "        is_invalid = True\n",
        "        break\n",
        "      if actors_dict[s_actor] < 2:\n",
        "        _dict['other_actor'] = 1\n",
        "      else:\n",
        "        _dict[s_actor] = 1\n",
        "    if is_invalid == True:\n",
        "      continue;\n",
        "    #regios\n",
        "    _dict[df_main.iloc[i]['region']] = 1\n",
        "    #userid ...\n",
        "    _dict[df_main.iloc[i]['USERID']] = 1\n",
        "    _dict[str(df_main.iloc[i]['movieid'])] = 1\n",
        "    _dict['rat'] = df_main.iloc[i]['rat']\n",
        "    _dict['rmax'] = df_main.iloc[i]['rmax']\n",
        "    _dict['rmin'] = df_main.iloc[i]['rmin']\n",
        "    _dict['ravg'] = df_main.iloc[i]['ravg']\n",
        "    _dict['rcount'] = df_main.iloc[i]['rcount']\n",
        "    _dict['rsum'] = df_main.iloc[i]['rsum']\n",
        "    _dict['rmedian'] = df_main.iloc[i]['rmedian']\n",
        "    _dict['TIME_DIS'] = df_main.iloc[i]['TIME_DIS']\n",
        "    #\n",
        "    #director\n",
        "    for s_director in df_main.iloc[i]['director'].split('|'):\n",
        "      if director_dict[s_director] < 2:\n",
        "        _dict['other_director'] = 1\n",
        "      else:\n",
        "        _dict[s_director] = 1\n",
        "    #trait\n",
        "    for s_trait in df_main.iloc[i]['trait'].split('|'):\n",
        "      _dict[s_trait] = 1\n",
        "    data_dict_list.append(_dict)\n",
        "  return data_dict_list"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "Orh9p8_XX7uP",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "df_data = df_data.fillna(0)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "4WJLcolxvB8A",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "dict_list = convert_dataframe_2_dict_list(df_data, actors_dict, director_dict)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "nY1h1uyGIOA2",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "dict_list"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "q79U_qXMWxJG",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "predict_X = v_from_pkl.transform(dict_list)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "xscCvdJUXNL2",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "#predict_X = scaler.transform(predict_X)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "hirUU3VNXZ2F",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "predict_file_ = '/content/drive/My Drive/colabnotebook/recsys_predict.txt'\n",
        "predict_file = '/content/drive/My\\ Drive/colabnotebook/recsys_predict.txt'\n",
        "\n",
        "dump_svmlight_file(predict_X, np.zeros(predict_X.shape[0]), predict_file_)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "1RLmjtAqXxfy",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "libfm_predict_final = FM(train_file, predict_file, classification=False)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "Wc4d-WRKYQY4",
        "colab_type": "code",
        "outputId": "b00d4397-6832-42cf-ea66-b65d8e33759a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 714
        }
      },
      "cell_type": "code",
      "source": [
        "libfm_predict_final"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([5.   , 5.   , 5.   , 4.7  , 4.76 , 4.756, 4.76 , 4.76 , 4.76 ,\n",
              "       4.75 , 4.758, 4.68 , 4.707, 4.756, 4.757, 4.76 , 4.737, 4.776,\n",
              "       4.76 , 4.76 , 4.707, 4.755, 4.734, 4.744, 4.748, 4.76 , 4.76 ,\n",
              "       4.707, 4.742, 4.76 , 4.76 , 4.749, 4.76 , 4.707, 4.707, 4.76 ,\n",
              "       4.759, 4.746, 4.707, 4.76 , 4.76 , 4.76 , 4.711, 4.757, 4.76 ,\n",
              "       4.804, 4.76 , 4.745, 4.76 , 4.76 , 4.744, 4.76 , 4.76 , 4.75 ,\n",
              "       4.76 , 4.762, 4.76 , 4.749, 4.757, 4.756, 4.704, 4.742, 4.757,\n",
              "       4.745, 4.756, 4.686, 4.76 , 4.739, 4.75 , 4.76 , 4.728, 4.744,\n",
              "       4.726, 4.76 , 4.69 , 4.756, 4.707, 4.76 , 4.757, 4.736, 4.759,\n",
              "       4.76 , 4.754, 4.76 , 4.76 , 4.698, 4.735, 4.756, 4.733, 4.691,\n",
              "       4.76 , 4.739, 4.75 , 4.714, 4.75 , 4.739, 4.76 , 4.756, 4.76 ,\n",
              "       4.716, 4.707, 4.76 , 4.753, 4.76 , 4.76 , 4.76 , 4.76 , 4.759,\n",
              "       4.76 , 4.68 , 4.715, 4.801, 4.658, 4.76 , 4.759, 4.76 , 4.726,\n",
              "       4.76 , 4.76 , 4.68 , 4.68 , 4.729, 4.733, 4.756, 4.752, 4.76 ,\n",
              "       4.72 , 4.748, 4.734, 4.76 , 4.691, 4.777, 4.738, 4.76 , 4.749,\n",
              "       4.749, 4.758, 4.757, 4.697, 4.764, 4.749, 4.76 , 4.733, 4.76 ,\n",
              "       4.711, 4.758, 4.746, 4.76 , 4.745, 4.754, 4.76 , 4.76 , 4.76 ,\n",
              "       4.788, 4.707, 4.76 , 4.76 , 4.763, 4.78 , 4.772, 4.758, 4.76 ,\n",
              "       4.71 , 4.76 , 4.76 , 4.76 , 4.76 , 4.76 , 4.76 , 4.718, 4.76 ,\n",
              "       4.792, 4.76 , 4.707, 4.763, 4.76 , 4.76 , 4.717, 4.755, 4.707,\n",
              "       4.76 , 4.76 , 4.761, 4.76 , 4.76 , 4.744, 4.751, 4.76 , 4.76 ,\n",
              "       4.682, 4.76 , 4.76 , 4.784, 4.724, 4.74 , 4.727, 4.757, 4.783,\n",
              "       4.752, 4.76 , 4.756, 4.76 , 4.754, 4.76 , 4.76 , 4.76 , 4.724,\n",
              "       4.76 , 4.759, 4.76 , 4.76 , 4.76 , 4.76 , 4.749, 4.74 , 4.721,\n",
              "       4.733, 4.756, 4.716, 4.76 , 4.718, 4.754, 4.759, 4.76 , 4.76 ,\n",
              "       4.742, 4.704, 4.752, 4.76 , 4.721, 4.723, 4.76 , 4.76 , 4.76 ,\n",
              "       4.717, 4.764, 4.714, 4.76 , 4.715, 4.725, 4.781, 4.73 , 4.76 ,\n",
              "       4.707, 4.76 , 4.76 , 4.765, 4.73 , 4.732, 4.76 , 4.691, 4.76 ,\n",
              "       4.76 , 4.76 , 4.712, 4.76 , 4.716, 4.76 , 4.76 , 4.76 , 4.76 ,\n",
              "       4.728, 4.76 , 4.76 , 4.75 , 4.76 , 4.76 , 4.76 , 4.76 , 4.752,\n",
              "       4.707, 4.719, 4.753, 4.76 , 4.76 , 4.76 , 4.76 , 4.75 , 4.76 ,\n",
              "       4.766, 4.747, 4.76 , 4.707, 4.755, 4.76 , 4.76 , 4.76 , 4.76 ,\n",
              "       4.748, 4.733, 4.718, 4.745, 4.742, 4.76 , 4.76 , 4.76 , 4.76 ,\n",
              "       4.76 , 4.721, 4.76 , 4.76 , 4.749, 4.766, 4.74 , 4.742, 4.75 ,\n",
              "       4.76 , 4.757, 4.76 , 4.76 , 4.729, 4.76 , 4.76 , 4.758, 4.738,\n",
              "       4.76 , 4.71 , 4.76 , 4.76 , 4.793, 4.76 , 4.742, 4.746, 4.755,\n",
              "       4.73 , 4.76 , 4.76 , 4.76 , 4.76 , 4.749, 4.76 , 4.707, 4.76 ,\n",
              "       4.753, 4.759, 4.76 , 4.76 , 4.76 , 4.7  , 4.75 , 4.749, 4.718,\n",
              "       4.718, 4.746, 4.76 , 4.76 , 4.76 , 4.76 , 4.743, 4.738, 4.76 ,\n",
              "       4.707, 4.715, 4.76 , 4.68 , 4.76 , 4.76 , 4.76 , 4.76 , 4.75 ,\n",
              "       4.76 , 4.76 , 4.76 , 4.698, 4.76 , 4.738, 4.76 , 4.76 ])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 51
        }
      ]
    },
    {
      "metadata": {
        "id": "tJuGlML7ZekI",
        "colab_type": "code",
        "outputId": "4bd08888-dc3f-4803-8a67-fe70d30b3fbf",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 542
        }
      },
      "cell_type": "code",
      "source": [
        "df_data"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>id</th>\n",
              "      <th>USERID</th>\n",
              "      <th>movieid</th>\n",
              "      <th>rectime</th>\n",
              "      <th>lrrat</th>\n",
              "      <th>fmrat</th>\n",
              "      <th>name</th>\n",
              "      <th>ADD_TIME</th>\n",
              "      <th>type</th>\n",
              "      <th>actors</th>\n",
              "      <th>...</th>\n",
              "      <th>enable</th>\n",
              "      <th>description</th>\n",
              "      <th>img</th>\n",
              "      <th>rmax</th>\n",
              "      <th>rmin</th>\n",
              "      <th>ravg</th>\n",
              "      <th>rcount</th>\n",
              "      <th>rsum</th>\n",
              "      <th>rmedian</th>\n",
              "      <th>TIME_DIS</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>10001432</td>\n",
              "      <td>2018-12-17 13:17:03</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>颠倒的帕特玛</td>\n",
              "      <td>2018-02-07 20:46:08</td>\n",
              "      <td>剧情|冒险|科幻|爱情</td>\n",
              "      <td>藤井雪代|冈本信彦|大畑伸太郎|福松进纱|加藤将之</td>\n",
              "      <td>...</td>\n",
              "      <td>1</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.00000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>4</td>\n",
              "      <td>1</td>\n",
              "      <td>10438426</td>\n",
              "      <td>2018-12-17 13:19:38</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>浮城谜事</td>\n",
              "      <td>2018-02-07 20:26:53</td>\n",
              "      <td>剧情|犯罪|悬疑|爱情</td>\n",
              "      <td>郝蕾|秦昊|齐溪|朱亚文|祖锋</td>\n",
              "      <td>...</td>\n",
              "      <td>1</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.00000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>10430817</td>\n",
              "      <td>2018-12-17 13:39:26</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>隐墙</td>\n",
              "      <td>2018-02-07 21:03:06</td>\n",
              "      <td>剧情|奇幻|悬疑|科幻</td>\n",
              "      <td>马蒂娜·格德克|Karlheinz Hackl|Wolfgang M|Bauer|Ulrik...</td>\n",
              "      <td>...</td>\n",
              "      <td>1</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.00000</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>5</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>10428476</td>\n",
              "      <td>2018-12-27 16:36:07</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>小屁孩日记3</td>\n",
              "      <td>2018-02-07 20:47:00</td>\n",
              "      <td>剧情|喜剧</td>\n",
              "      <td>扎克瑞·戈登|瑞秋·哈里斯|戴文·博斯蒂克|罗伯特·卡普荣|佩顿·李斯特</td>\n",
              "      <td>...</td>\n",
              "      <td>1</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>5.0</td>\n",
              "      <td>2.0</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>7.0</td>\n",
              "      <td>27.0</td>\n",
              "      <td>4.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>6</td>\n",
              "      <td>cf2349f9c01f9a5cd4050aebd30ab74f</td>\n",
              "      <td>10480973</td>\n",
              "      <td>2018-12-27 16:39:34</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>圣斗士星矢：圣域传说</td>\n",
              "      <td>2018-02-07 20:38:14</td>\n",
              "      <td>奇幻|冒险|科幻|动作</td>\n",
              "      <td>石川界人|赤羽根健治|小野贤章|冈本信彦|野岛健儿</td>\n",
              "      <td>...</td>\n",
              "      <td>1</td>\n",
              "      <td></td>\n",
              "      <td></td>\n",
              "      <td>5.0</td>\n",
              "      <td>2.0</td>\n",
              "      <td>3.85714</td>\n",
              "      <td>7.0</td>\n",
              "      <td>27.0</td>\n",
              "      <td>4.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 24 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "  id                            USERID   movieid             rectime lrrat  \\\n",
              "0  1                                 1  10001432 2018-12-17 13:17:03         \n",
              "1  4                                 1  10438426 2018-12-17 13:19:38         \n",
              "2  2                                 1  10430817 2018-12-17 13:39:26         \n",
              "3  5  cf2349f9c01f9a5cd4050aebd30ab74f  10428476 2018-12-27 16:36:07         \n",
              "4  6  cf2349f9c01f9a5cd4050aebd30ab74f  10480973 2018-12-27 16:39:34         \n",
              "\n",
              "  fmrat        name             ADD_TIME         type  \\\n",
              "0            颠倒的帕特玛  2018-02-07 20:46:08  剧情|冒险|科幻|爱情   \n",
              "1              浮城谜事  2018-02-07 20:26:53  剧情|犯罪|悬疑|爱情   \n",
              "2                隐墙  2018-02-07 21:03:06  剧情|奇幻|悬疑|科幻   \n",
              "3            小屁孩日记3  2018-02-07 20:47:00        剧情|喜剧   \n",
              "4        圣斗士星矢：圣域传说  2018-02-07 20:38:14  奇幻|冒险|科幻|动作   \n",
              "\n",
              "                                              actors    ...    enable  \\\n",
              "0                          藤井雪代|冈本信彦|大畑伸太郎|福松进纱|加藤将之    ...         1   \n",
              "1                                    郝蕾|秦昊|齐溪|朱亚文|祖锋    ...         1   \n",
              "2  马蒂娜·格德克|Karlheinz Hackl|Wolfgang M|Bauer|Ulrik...    ...         1   \n",
              "3               扎克瑞·戈登|瑞秋·哈里斯|戴文·博斯蒂克|罗伯特·卡普荣|佩顿·李斯特    ...         1   \n",
              "4                          石川界人|赤羽根健治|小野贤章|冈本信彦|野岛健儿    ...         1   \n",
              "\n",
              "  description img rmax rmin     ravg rcount  rsum  rmedian  TIME_DIS  \n",
              "0                  0.0  0.0  0.00000    0.0   0.0      0.0       0.0  \n",
              "1                  0.0  0.0  0.00000    0.0   0.0      0.0       0.0  \n",
              "2                  0.0  0.0  0.00000    0.0   0.0      0.0       0.0  \n",
              "3                  5.0  2.0  3.85714    7.0  27.0      4.0       0.0  \n",
              "4                  5.0  2.0  3.85714    7.0  27.0      4.0       0.0  \n",
              "\n",
              "[5 rows x 24 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 125
        }
      ]
    },
    {
      "metadata": {
        "id": "n5-7yejX-_zl",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## 更新推荐电影recmovie表的FM预测打分或LR的点击概率"
      ]
    },
    {
      "metadata": {
        "id": "PPZnhJN2Zg0R",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "def update_recmovie_rat(id, rat, connection, model_type):\n",
        "  rat_field = None\n",
        "  if model_type == 'LR':\n",
        "    rat_field = 'recmovie.lrrat'\n",
        "  elif model_type == 'FM':\n",
        "    rat_field = 'recmovie.fmrat'\n",
        "    \n",
        "  sql = 'update recmovie set %s = %s where id = %s' % (rat_field, rat, id)\n",
        "  try:\n",
        "      with connection.cursor() as cursor:\n",
        "          cout=cursor.execute(sql)\n",
        "      connection.commit()\n",
        "  except:\n",
        "      connection.close()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "cpdjogFgkimt",
        "colab_type": "code",
        "outputId": "fc97a233-2452-4be7-9678-e987de6569ab",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "df_data.iloc[0]['id']"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'1'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 62
        }
      ]
    },
    {
      "metadata": {
        "id": "86ETdzmh_UaU",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## 调用FM打分"
      ]
    },
    {
      "metadata": {
        "id": "lzitc6BXkLxu",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "def update_FM_rat(df_data, libfm_predict_final):\n",
        "  index_ = 0\n",
        "  for r in libfm_predict_final:\n",
        "    update_recmovie_rat(df_data.iloc[index_]['id'], r, get_connection(), 'FM')\n",
        "    index_ = index_ + 1"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "b2fK-4Q4ktPa",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "update_FM_rat(df_data, libfm_predict_final)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "GMFBCUWCo2iz",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_file_lr_path = '/content/drive/My Drive/colabnotebook/recsys_train_scaling_lr.txt'\n",
        "test_file_lr_path = '/content/drive/My Drive/colabnotebook/recsys_test_scaling_lr.txt'"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "5uZ2NHEHZcdT",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_lr_path = '/content/drive/My Drive/colabnotebook/recsys_train_lr.txt'"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "l5Zo5X-koBcV",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_X_lr, train_y = get_test_data(train_lr_path)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "f6_sfd1DpApJ",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "test_X_lr, test_y = get_test_data(test_file_lr_path)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "D3QhfPzM_XNO",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## LR模型fit"
      ]
    },
    {
      "metadata": {
        "id": "hMewIi5glcKn",
        "colab_type": "code",
        "outputId": "283c0cf3-fd5e-4cb6-e96e-775f30177205",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 139
        }
      },
      "cell_type": "code",
      "source": [
        "lr = LogisticRegression(C=0.01,penalty='l2')\n",
        "lr.fit(train_X_lr,train_y)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/usr/local/lib/python3.6/dist-packages/sklearn/linear_model/logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
            "  FutureWarning)\n"
          ],
          "name": "stderr"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "LogisticRegression(C=0.01, class_weight=None, dual=False, fit_intercept=True,\n",
              "          intercept_scaling=1, max_iter=100, multi_class='warn',\n",
              "          n_jobs=None, penalty='l2', random_state=None, solver='warn',\n",
              "          tol=0.0001, verbose=0, warm_start=False)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 195
        }
      ]
    },
    {
      "metadata": {
        "id": "8036vdjpRI5L",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "train_X_4_scale, train_y_4_scale = get_test_data(train_lr_path)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "s5kU8FV2Rec5",
        "colab_type": "code",
        "outputId": "97651e35-cfe5-4b64-84fc-46e79662078f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "train_X_4_scale.shape"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(280000, 75619)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 197
        }
      ]
    },
    {
      "metadata": {
        "id": "b7y2F5n_RKqi",
        "colab_type": "code",
        "outputId": "018cffa8-03b0-444e-93eb-dfe3c9ab8b84",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "train_y_4_scale[train_y_4_scale == 1].shape"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(159626,)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 132
        }
      ]
    },
    {
      "metadata": {
        "id": "rZx3u30b_ifx",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## 最终实现代码参考recsys_core"
      ]
    },
    {
      "metadata": {
        "id": "bwSNcSS3QlFC",
        "colab_type": "code",
        "outputId": "d8b98aa4-300a-4a1b-99cc-96618aa63469",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "from sklearn import preprocessing\n",
        "\n",
        "scaler = preprocessing.MaxAbsScaler()\n",
        "scaler.fit(train_X_4_scale)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "MaxAbsScaler(copy=True)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 233
        }
      ]
    },
    {
      "metadata": {
        "id": "nnc0bN-PVm6-",
        "colab_type": "code",
        "outputId": "326f33e6-0ff8-450e-f0d9-978b6417a9f6",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        }
      },
      "cell_type": "code",
      "source": [
        "temp_one = v_from_pkl.transform({'1': 1,\n",
        "  '10430817': 1,\n",
        "  'TIME_DIS': 0.0,\n",
        "  'other_actor': 1,\n",
        "  'other_director': 1,\n",
        "  'rat': '7.4',\n",
        "  'ravg': 3.0,\n",
        "  'rcount': 1.0,\n",
        "  'rmax': 3.0,\n",
        "  'rmedian': 3.0,\n",
        "  'rmin': 3.0,\n",
        "  'rsum': 3.0,\n",
        "  '剧情': 1,\n",
        "  '奇幻': 1,\n",
        "  '德国': 1,\n",
        "  '悬疑': 1,\n",
        "  '文艺': 1,\n",
        "  '科幻': 1,\n",
        "  '马蒂娜·格德克': 1})\n",
        "\n",
        "temp_one = v_from_pkl.transform({'1': 1,\n",
        "  '10430817': 1,\n",
        "  'TIME_DIS': 0.0,\n",
        "  'other_actor': 1,\n",
        "  'other_director': 1,\n",
        "  'rat': '7.4',\n",
        "  'ravg': 3.0,\n",
        "  'rcount': 100.0,\n",
        "  'rmax': 3.0,\n",
        "  'rmedian': 3.0,\n",
        "  'rmin': 3.0,\n",
        "  'rsum': 3.0,\n",
        "  '剧情': 1,\n",
        "  '奇幻': 1,\n",
        "  '德国': 1,\n",
        "  '悬疑': 1,\n",
        "  '文艺': 1,\n",
        "  '科幻': 1,\n",
        "  '马蒂娜·格德克': 1})\n",
        "temp_one[temp_one != 0]"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "matrix([[  1.,   1.,   1.,   3., 100.,   3.,   3.,   3.,   3.,   1.,\n",
              "           1.,   1.,   1.,   1.,   1.,   1.]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 234
        }
      ]
    },
    {
      "metadata": {
        "id": "4AhDNyG7VtYm",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "temp_one_X = scaler.transform(temp_one)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "Mc3EiRpke-XT",
        "colab_type": "code",
        "outputId": "60101dd8-ac1d-4e68-bae0-417229b0f580",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        }
      },
      "cell_type": "code",
      "source": [
        "temp_one_X[temp_one_X != 0]"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "matrix([[1.   , 1.   , 1.   , 0.6  , 0.035, 0.6  , 0.6  , 0.6  , 0.   ,\n",
              "         1.   , 1.   , 1.   , 1.   , 1.   , 1.   , 1.   ]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 236
        }
      ]
    },
    {
      "metadata": {
        "id": "MsPbGIc6RhwC",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "predict_X = scaler.transform(predict_X)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "mlx97ExLpwVh",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "lr_predict_final = lr.predict_proba(temp_one)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "24FU5lqXQfAf",
        "colab_type": "code",
        "outputId": "6f461cab-4797-4c95-ec89-7b8b3b6b9f46",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "lr_predict_final"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[0.032, 0.968]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 218
        }
      ]
    },
    {
      "metadata": {
        "id": "QcT5gPQ3_pHw",
        "colab_type": "text"
      },
      "cell_type": "markdown",
      "source": [
        "## 调用更新LR点击概率"
      ]
    },
    {
      "metadata": {
        "id": "X7YN7XWlpfRj",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "def update_LR_rat(df_data, lr_predict_final):\n",
        "  index_ = 0\n",
        "  for r in lr_predict_final:\n",
        "    update_recmovie_rat(df_data.iloc[index_]['id'], r[1], get_connection(), 'LR')\n",
        "    index_ = index_ + 1"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "t0moIZIdwIDb",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "update_LR_rat(df_data, lr_predict_final.tolist())"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "UijTWjgUp4Ip",
        "colab_type": "code",
        "outputId": "bd3aeaec-7de2-4f36-f221-0feba6840475",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "train_X_lr.shape, test_X_lr.shape"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "((280000, 75619), (9152, 75615))"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 153
        }
      ]
    },
    {
      "metadata": {
        "id": "CjbSddBFqdKs",
        "colab_type": "code",
        "outputId": "cb0b7d74-b79a-4ee3-c92b-8271e0ffc249",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "X.shape"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(9152, 75615)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 155
        }
      ]
    },
    {
      "metadata": {
        "id": "emsK5JLhsNde",
        "colab_type": "code",
        "outputId": "232393fb-a67e-440d-98ec-41bcd95e201b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        }
      },
      "cell_type": "code",
      "source": [
        "predict_X"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<5x75619 sparse matrix of type '<class 'numpy.float64'>'\n",
              "\twith 94 stored elements in Compressed Sparse Row format>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 175
        }
      ]
    },
    {
      "metadata": {
        "id": "lhnypRDqtDTX",
        "colab_type": "code",
        "outputId": "5a143d52-9670-4e43-83b5-f4c3ec0a6271",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        }
      },
      "cell_type": "code",
      "source": [
        "lr.classes_"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([0., 1.])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 163
        }
      ]
    },
    {
      "metadata": {
        "id": "er6O9kdstZfc",
        "colab_type": "code",
        "outputId": "f8cd9bf7-a408-4802-e284-857b540d97e9",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        }
      },
      "cell_type": "code",
      "source": [
        "lr_predict_final.tolist()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[[0.9976049939496754, 0.0023950060503245886],\n",
              " [0.9998143586577533, 0.00018564134224680022],\n",
              " [0.9983921456376658, 0.0016078543623342142],\n",
              " [0.0, 1.0],\n",
              " [0.0, 1.0]]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 176
        }
      ]
    },
    {
      "metadata": {
        "id": "HfJgC3Lcx-mQ",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}